package com.group4.highschoolportal.teacher.backingBeans;

import com.group4.entity.Course;
import com.group4.entity.Lesson;
import com.group4.entity.Teacher;
import java.util.List;
import java.io.Serializable;
import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;




/**
 *
 * @author Victor Cernea
 */
@ManagedBean
@SessionScoped
public class TeacherLessonsBackingBean implements Serializable  {
    private Teacher teacher;
    private List<Lesson> lessons;

    public TeacherLessonsBackingBean(){
    HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
    teacher = (Teacher) session.getAttribute("user");
    lessons = new ArrayList<Lesson>();
    }

    @PostConstruct
    private void init() {
        List<Course> courses = teacher.getList();
        for (Course c : courses) {
            for (Lesson l : c.getLesson()) {
                lessons.add(l);
            }
        }
        
    }

    public List<Lesson> getLessons() {
        return lessons;
    }

    public void setLessons(List<Lesson> lessons) {
        this.lessons = lessons;
    }

    public Teacher getTeacher() {
        return teacher;
    }

    public void setTeacher(Teacher teacher) {
        this.teacher = teacher;
    }
    
    
    
}
